﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbNewOrderProdListDal
	{
		public DbNewOrderProdListDal()
		{
		}
 		#region Insert
 		public static int Insert(DbNewOrderProdList dbNewOrderProdList)
		{	
			string sql = @"Insert Into DbNewOrderProdList (
					OrderSN,
					PId,
					PName,
					PCode,
					PColor,
					PSize,
					PPic,
					PWeight,
					PPrice,
					Remarks,
					AddTime,
					Qty,
					PImage
				) values('{0}',{1},'{2}','{3}','{4}','{5}','{6}',{7},{8},'{9}','{10}',{11},'{12}')";
			sql = string.Format(sql,
					SqlHelper.String(dbNewOrderProdList.OrderSN),
					dbNewOrderProdList.PId,
					SqlHelper.String(dbNewOrderProdList.PName),
					SqlHelper.String(dbNewOrderProdList.PCode),
					SqlHelper.String(dbNewOrderProdList.PColor),
					SqlHelper.String(dbNewOrderProdList.PSize),
					SqlHelper.String(dbNewOrderProdList.PPic),
					dbNewOrderProdList.PWeight,
					dbNewOrderProdList.PPrice,
					SqlHelper.String(dbNewOrderProdList.Remarks),
					dbNewOrderProdList.AddTime,
					dbNewOrderProdList.Qty,
					SqlHelper.String(dbNewOrderProdList.PImage)
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbNewOrderProdList dbNewOrderProdList)
		{	
			string sql = @"Update DbNewOrderProdList set 

					OrderSN= '{0}',
					PId= {1},
					PName= '{2}',
					PCode= '{3}',
					PColor= '{4}',
					PSize= '{5}',
					PPic= '{6}',
					PWeight= {7},
					PPrice= {8},
					Remarks= '{9}',
					AddTime= '{10}',
					Qty= {11},
					PImage= '{12}'
				where

					CId= {13}";
			sql = string.Format(sql,
					SqlHelper.String(dbNewOrderProdList.OrderSN),
					dbNewOrderProdList.PId,
					SqlHelper.String(dbNewOrderProdList.PName),
					SqlHelper.String(dbNewOrderProdList.PCode),
					SqlHelper.String(dbNewOrderProdList.PColor),
					SqlHelper.String(dbNewOrderProdList.PSize),
					SqlHelper.String(dbNewOrderProdList.PPic),
					dbNewOrderProdList.PWeight,
					dbNewOrderProdList.PPrice,
					SqlHelper.String(dbNewOrderProdList.Remarks),
					dbNewOrderProdList.AddTime,
					dbNewOrderProdList.Qty,
					SqlHelper.String(dbNewOrderProdList.PImage),
					dbNewOrderProdList.CId);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 cId)
		{
		
			string sql = @"Delete from DbNewOrderProdList where 
					CId= {0}";
			sql = string.Format(sql,
					cId
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbNewOrderProdList a "; 
			return SqlHelper.Select(sql);
		}
				
		public static DbNewOrderProdList Select(Int32 cId)
		{
			DbNewOrderProdList dbNewOrderProdList = null;
			string sql = @"select a.* from DbNewOrderProdList a  where
					a.CId= {0}
";
			sql = string.Format(sql,
					cId
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				dbNewOrderProdList = new DbNewOrderProdList(ds.Tables[0].Rows[0]);					
			return dbNewOrderProdList;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbNewOrderProdList a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbNewOrderProdList a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbNewOrderProdList a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
